package cn.gzsxt.music.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.gzsxt.music.mapper.UserCollectMapper;
import cn.gzsxt.music.query.UserCollectQueryObject;
import cn.gzsxt.music.service.UserCollectServcie;

@Service
public class UserCollectServiceImpl implements UserCollectServcie {
	
	@Autowired
	private UserCollectMapper mapper;

	@Override
	public Map<String, Object> selectUsListByQo(UserCollectQueryObject qo) {
		Map<String, Object> dataGridMap1 = new HashMap<>();
		dataGridMap1.put("total", mapper.selectUsTotalByQo(qo));
		dataGridMap1.put("rows", mapper.selectUsListByQo(qo));
		return dataGridMap1;
	}

	@Override
	public Map<String, Object> selectUcListByQo(UserCollectQueryObject qo) {
		Map<String, Object> dataGridMap2 = new HashMap<>();
		dataGridMap2.put("total", mapper.selectUcTotalByQo(qo));
		dataGridMap2.put("rows", mapper.selectUcListByQo(qo));
		return dataGridMap2;
	}

	@Override
	public Map<String, Object> selectUsrListByQo(UserCollectQueryObject qo) {
		Map<String, Object> dataGridMap3 = new HashMap<>();
		dataGridMap3.put("total", mapper.selectUsrTotalByQo(qo));
		dataGridMap3.put("rows", mapper.selectUsrListByQo(qo));
		return dataGridMap3;
	}

	@Override
	public List<Map<String, Object>> getAllCds() {
		return mapper.getAllCds();
	}

	@Override
	public int insertUcList(Map<String, Object> params) {
		int row = 0;
		int row1 = mapper.insertUcList(params);
		int row2 = mapper.updateCd(params);
		if (row1 != 0 && row2 != 0) {
			row = 1;
			return row;
		}
		return row;
	}

	@Override
	public int updateUcList(Map<String, Object> params) {
		return mapper.updateUcList(params);
	}

	@Override
	public int deleteUcListById(Long ucList_id) {
		return mapper.deleteUcListById(ucList_id);
	}

	@Override
	public int insertUsList(Map<String, Object> params) {
		String songList_name = (String) params.get("songList_name");
		List<Map<String, Object>> songList = mapper.getSongListByName(songList_name);
		int row = 0;
		int row1;
		int row2 = 0;
		if (songList.size() == 0) {
			row1 = mapper.insertSongList(params);
			if (row1 == 1) {
				row2 = mapper.inserUsList(params);
			}
		}else {
			Map<String, Object> map = songList.get(0);
			Object songList_id = map.get("songList_id");
			params.put("songList_id", songList_id);
			row1 = mapper.updateSongList(params);
			row2 = mapper.inserUsList(params);
		}
		if (row1 != 0 && row2 != 0) {
			row = 1;
			return row;
		}
		return row;
	}

	@Override
	public List<Map<String, Object>> checkSongListByName(String songList_name) {
		return mapper.getSongListByName(songList_name);
	}

	@Override
	public int updateUsList(Map<String, Object> params) {
		return mapper.updateUsList(params);
	}

	@Override
	public int deleteUsListById(Long usList_id) {
		return mapper.deleteUsListById(usList_id);
	}

	@Override
	public List<Map<String, Object>> getAllSingers() {
		return mapper.getAllSingers();
	}

	@Override
	public int insertUsrList(Map<String, Object> params) {
		int row = 0;
		int row1 = mapper.insertUsrList(params);
		int row2 = mapper.updateSinger(params);
		if (row1 != 0 && row2 != 0) {
			row = 1;
			return row;
		}
		return row;
	}

	@Override
	public int updateUsrList(Map<String, Object> params) {
		return mapper.updateUsrList(params);
	}

	@Override
	public int deleteUsrListById(Long usrList_id) {
		return mapper.deleteUsrListById(usrList_id);
	}

	@Override
	public Long checkUsByUnameAndSname(Map<String, Object> params) {
		
		return mapper.checkUsByUnameAndSname(params);
	}

	@Override
	public Long checkUcByUnameAndCid(Map<String, Object> params) {
		
		return mapper.checkUcByUnameAndCid(params);
	}

	@Override
	public Long checkUsrByUnameAndRid(Map<String, Object> params) {
		return mapper.checkUsrByUnameAndRid(params);
	}
}
